package com.example.goodsprovider.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.myshop.b2b.commonmodule.Goods;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
* @author likaiping
* @description 针对表【goods】的数据库操作Mapper
* @createDate 2024-07-03 15:07:29
* @Entity com.example.goodsprovider.pojo.Goods
*/
public interface GoodsMapper extends BaseMapper<Goods> {
    /**
     * 查询所有商品
     * @return
     */
    @Select("select * from goods")
    List<Goods> getAllgoods();

    /**
     * 根据商品名称模糊查找
     * @param gname
     * @return
     */
    @Select("SELECT * FROM goods WHERE gname LIKE \"%${gname}%\"")
    List<Goods> getOnegoods(@Param(value = "gname")String gname);

    /**
     * 根据id查询单个商品详情
     * @param gid
     * @return
     */
    @Select("select * from goods where gid=#{gid}")
    Goods getOnegid(@Param(value = "gid")int gid);

    /**
     * 减库存
     * @param gid
     * @param number
     * @return
     */
    @Update("update goods set stock=stock-#{number} where gid=#{gid}")
    boolean updateGoodsStock(@Param("gid") int gid, @Param("number") Integer number);
}




